home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Include / GuiEdit.au3 < prev    next >
Encoding:
Text File  |  2007-09-08  |  36.8 KB  |  761 lines

  1. #include-once
  2.  
  3. #include <EditConstants.au3> ; needed for _GuiCtrlEditFind
  4. #include <GuiStatusBar.au3> ; needed for _GuiCtrlEditFind
  5. #include <GUIConstantsEx.au3>
  6. #include <StaticConstants.au3>
  7. #include <Memory.au3>
  8. #include <Misc.au3>
  9. ; ------------------------------------------------------------------------------
  10. ;
  11. ; AutoIt Version: 3.2.3++
  12. ; Language:       English
  13. ; Description:    Functions that assist with Edit control.
  14. ;
  15. ; ------------------------------------------------------------------------------
  16.  
  17.  
  18. ; function list
  19. ;===============================================================================
  20. ; _GUICtrlEditCanUndo
  21. ; _GuiCtrlEditFind
  22. ; _GUICtrlEditEmptyUndoBuffer
  23. ; _GUICtrlEditGetFirstVisibleLine
  24. ; _GUICtrlEditGetLine
  25. ; _GUICtrlEditGetLineCount
  26. ; _GUICtrlEditGetModify
  27. ; _GUICtrlEditGetRECT
  28. ; _GUICtrlEditGetSel
  29. ; _GUICtrlEditLineFromChar
  30. ; _GUICtrlEditLineIndex
  31. ; _GUICtrlEditLineLength
  32. ; _GUICtrlEditLineScroll
  33. ; _GUICtrlEditReplaceSel
  34. ; _GUICtrlEditScroll
  35. ; _GUICtrlEditSetModify
  36. ; _GUICtrlEditSetRECT
  37. ; _GUICtrlEditSetSel
  38. ; _GUICtrlEditUndo
  39. ;===============================================================================
  40. ; Helper Function(s)
  41. ; _GuiCtrlEditFindText
  42. ;===============================================================================
  43. ;
  44. ; Description:            _GUICtrlEditCanUndo
  45. ; Parameter(s):        $h_edit - controlID
  46. ; Requirement:            None
  47. ; Return Value(s):    If there are actions in the control's undo queue, the return value is nonzero.
  48. ;                            If the undo queue is empty, the return value is zero.
  49. ; User CallTip:        _GUICtrlEditCanUndo($h_edit) Determines whether there are any actions in an edit control's undo queue. (required: <GuiEdit.au3>)
  50. ; Author(s):            Gary Frost (custompcs at charter dot net)
  51. ; Note(s):                If the undo queue is not empty, you can call the _GUICtrlEditUndo
  52. ;                            to undo the most recent operation.
  53. ;
  54. ;===============================================================================
  55. Func _GUICtrlEditCanUndo($h_Edit)
  56.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, 0)
  57.     If IsHWnd($h_Edit) Then
  58.         Return _SendMessage($h_Edit, $EM_CANUNDO)
  59.     Else
  60.         Return GUICtrlSendMsg($h_Edit, $EM_CANUNDO, 0, 0)
  61.     EndIf
  62.  
  63. EndFunc   ;==>_GUICtrlEditCanUndo
  64.  
  65. ;===============================================================================
  66. ;
  67. ; Description:            _GUICtrlEditEmptyUndoBuffer
  68. ; Parameter(s):        $h_edit - controlID
  69. ; Requirement:            None
  70. ; Return Value(s):    None
  71. ; User CallTip:        _GUICtrlEditEmptyUndoBuffer($h_edit) Resets the undo flag of an edit control. (required: <GuiEdit.au3>)
  72. ; Author(s):            Gary Frost (custompcs at charter dot net)
  73. ; Note(s):                The undo flag is automatically reset whenever the edit control receives a WM_SETTEXT or EM_SETHANDLE message.
  74. ;                            The control can only undo or redo the most recent operation.
  75. ;
  76. ;===============================================================================
  77. Func _GUICtrlEditEmptyUndoBuffer($h_Edit)
  78.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, 0)
  79.     If IsHWnd($h_Edit) Then
  80.         _SendMessage($h_Edit, $EM_EMPTYUNDOBUFFER)
  81.     Else
  82.         GUICtrlSendMsg($h_Edit, $EM_EMPTYUNDOBUFFER, 0, 0)
  83.     EndIf
  84. EndFunc   ;==>_GUICtrlEditEmptyUndoBuffer
  85.  
  86. ;===============================================================================
  87. ;
  88. ; Description:            _GuiCtrlEditFind
  89. ; Parameter(s):        $h_gui - GUI ID/Window Handle (Handle only be used with external controls)
  90. ;                            $h_edit - control ID/Control Handle (Handle only be used with external controls)
  91. ;                            $b_replace - Optional: Boolean True/False show replace option (Default is False)
  92. ;                            $s_WinTitle - Optional: Window Title (should only be used with external controls)
  93. ;                            $s_WinText - Optional: Window Text (should only be used with external controls)
  94. ; Requirement:            $ES_NOHIDESEL style should be used with edit control
  95. ; Return Value(s):    None
  96. ; User CallTip:        _GuiCtrlEditFind(ByRef $h_gui, ByRef $h_edit[, $b_replace = False[, $s_WinTitle = ""[, $s_WinText = ""]]]) Find/Replace text in an Edit control. (required: <GuiEdit.au3>)
  97. ; Author(s):            Gary Frost (custompcs at charter dot net)
  98. ; Note(s):                Be careful using the $s_WinText
  99. ;                    if you use text from the edit control and that text gets replaced
  100. ;                    the function will no longer function correctly
  101. ;
  102. ;===============================================================================
  103. Func _GuiCtrlEditFind(ByRef $h_gui, ByRef $h_Edit, $b_replace = False, $s_WinTitle = "", $s_WinText = "")
  104.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, 0)
  105.     Local $gui_Search, $Input_Search, $Input_Replace, $lbl_replace, $msg_find
  106.     Local $pos = 0, $case, $occurance = 0, $Replacements = 0
  107.     Local $chk_wholeonly, $chk_matchcase, $btn_FindNext, $btn_replace, $btn_close, $StatusBar1
  108.     Local $s_text, $a_sel
  109.     Local $a_PartsRightEdge[3] = [125, 225, -1]
  110.     Local $a_PartsText[3] = ["", "", ""], $t_pos
  111.     If $s_WinTitle <> "" Then
  112.         $s_text = ControlGetText($s_WinTitle, $s_WinText, $h_Edit)
  113.         $a_sel = _GUICtrlEditGetSel($h_Edit)
  114.     Else
  115.         $s_text = GUICtrlRead($h_Edit)
  116.         $a_sel = _GUICtrlEditGetSel($h_Edit)
  117.     EndIf
  118.  
  119.     $gui_Search = GUICreate("Find", 349, 177, -1, -1, BitOR($WS_CHILD, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU), -1, $h_gui)
  120.     $StatusBar1 = _GUICtrlStatusBarCreate($gui_Search, $a_PartsRightEdge, $a_PartsText)
  121.     _GUICtrlStatusBarSetText($StatusBar1, "Find: ", 0)
  122.     
  123.     GUISetIcon(@SystemDir & "\shell32.dll", 22, $gui_Search)
  124.     GUICtrlCreateLabel("Find what:", 9, 10, 53, 16, $SS_CENTER)
  125.     $Input_Search = GUICtrlCreateInput("", 80, 8, 257, 21)
  126.     If (IsArray($a_sel) And $a_sel <> $EC_ERR) Then
  127.         GUICtrlSetData($Input_Search, StringMid($s_text, $a_sel[1] + 1, $a_sel[2] - $a_sel[1]))
  128.         If $a_sel[1] <> $a_sel[2] Then ; text was selected when function was invoked
  129.             $pos = $a_sel[1]
  130.             If BitAND(GUICtrlRead($chk_matchcase), $GUI_CHECKED) = $GUI_CHECKED Then $case = 1
  131.             $occurance = 1
  132.             While 1 ; set the current occurance so search starts from here
  133.                 $t_pos = StringInStr($s_text, GUICtrlRead($Input_Search), $case, $occurance)
  134.                 If Not $t_pos Then ; this should never happen, but just in case
  135.                     $occurance = 0
  136.                     ExitLoop
  137.                 ElseIf $t_pos = $pos + 1 Then ; found the occurance
  138.                     ExitLoop
  139.                 EndIf
  140.                 $occurance += 1
  141.             WEnd
  142.         EndIf
  143.         _GUICtrlStatusBarSetText($StatusBar1, "Find: " & GUICtrlRead($Input_Search), 0)
  144.     EndIf
  145.     $lbl_replace = GUICtrlCreateLabel("Replace with:", 9, 42, 69, 17, $SS_CENTER)
  146.     $Input_Replace = GUICtrlCreateInput("", 80, 40, 257, 21)
  147.     $chk_wholeonly = GUICtrlCreateCheckbox("Match whole word only", 9, 72, 145, 17)
  148.     $chk_matchcase = GUICtrlCreateCheckbox("Match case", 9, 96, 145, 17)
  149.     $btn_FindNext = GUICtrlCreateButton("Find Next", 168, 72, 161, 21, 0)
  150.     $btn_replace = GUICtrlCreateButton("Replace", 168, 96, 161, 21, 0)
  151.     $btn_close = GUICtrlCreateButton("Close", 104, 130, 161, 21, 0)
  152.     
  153.     If $b_replace = False Then
  154.         GUICtrlSetState($lbl_replace, $GUI_HIDE)
  155.         GUICtrlSetState($Input_Replace, $GUI_HIDE)
  156.         GUICtrlSetState($btn_replace, $GUI_HIDE)
  157.     Else
  158.         _GUICtrlStatusBarSetText($StatusBar1, "Replacements: " & $Replacements, 1)
  159.         _GUICtrlStatusBarSetText($StatusBar1, "With: ", 2)
  160.     EndIf
  161.     GUISetState(@SW_SHOW)
  162.  
  163.     While 1
  164.         $msg_find = GUIGetMsg()
  165.         Select
  166.             Case $msg_find = $GUI_EVENT_CLOSE Or $msg_find = $btn_close
  167.                 ExitLoop
  168.             Case $msg_find = $btn_FindNext
  169.                 GUICtrlSetState($btn_FindNext, $GUI_DISABLE)
  170.                 GUICtrlSetCursor($btn_FindNext, 15)
  171.                 Sleep(100)
  172.                 _GUICtrlStatusBarSetText($StatusBar1, "Find: " & GUICtrlRead($Input_Search), 0)
  173.                 If $b_replace = True Then
  174.                     _GUICtrlStatusBarSetText($StatusBar1, "Find: " & GUICtrlRead($Input_Search), 0)
  175.                     _GUICtrlStatusBarSetText($StatusBar1, "With: " & GUICtrlRead($Input_Replace), 2)
  176.                 EndIf
  177.                 _GuiCtrlEditFindText($h_Edit, $Input_Search, $chk_matchcase, $chk_wholeonly, $pos, $occurance, $Replacements, $s_WinTitle, $s_WinText)
  178.                 Sleep(100)
  179.                 GUICtrlSetState($btn_FindNext, $GUI_ENABLE)
  180.                 GUICtrlSetCursor($btn_FindNext, 2)
  181.             Case $msg_find = $btn_replace
  182.                 GUICtrlSetState($btn_replace, $GUI_DISABLE)
  183.                 GUICtrlSetCursor($btn_replace, 15)
  184.                 Sleep(100)
  185.                 _GUICtrlStatusBarSetText($StatusBar1, "Find: " & GUICtrlRead($Input_Search), 0)
  186.                 _GUICtrlStatusBarSetText($StatusBar1, "With: " & GUICtrlRead($Input_Replace), 2)
  187.                 If $pos Then
  188.                     _GUICtrlEditReplaceSel($h_Edit, True, GUICtrlRead($Input_Replace))
  189.                     $Replacements += 1
  190.                     $occurance -= 1
  191.                     _GUICtrlStatusBarSetText($StatusBar1, "Replacements: " & $Replacements, 1)
  192.                 EndIf
  193.                 _GuiCtrlEditFindText($h_Edit, $Input_Search, $chk_matchcase, $chk_wholeonly, $pos, $occurance, $Replacements, $s_WinTitle, $s_WinText)
  194.                 Sleep(100)
  195.                 GUICtrlSetState($btn_replace, $GUI_ENABLE)
  196.                 GUICtrlSetCursor($btn_replace, 2)
  197.         EndSelect
  198.     WEnd
  199.     GUIDelete($gui_Search)
  200. EndFunc   ;==>_GuiCtrlEditFind
  201.  
  202. ;===============================================================================
  203. ;
  204. ; Description:            _GuiCtrlEditFindText
  205. ; Parameter(s):        $h_edit - controlID
  206. ;                            $Input_Search - controlID
  207. ;                            $chk_matchcase - controlID
  208. ;                            $chk_wholeonly - controlID
  209. ;                            $pos - position of text found
  210. ;                            $occurance - occurance to find
  211. ;                            $Replacements - # of occurances replaced
  212. ;                            $s_WinTitle - Optional: Window Title
  213. ;                            $s_WinText - Optional: Window Text
  214. ; Requirement:            _GuiCtrlEditFind function
  215. ; Return Value(s):    None
  216. ; User CallTip:
  217. ; Author(s):            Gary Frost (custompcs at charter dot net)
  218. ; Note(s):
  219. ;
  220. ;===============================================================================
  221. Func _GuiCtrlEditFindText(ByRef $h_Edit, ByRef $Input_Search, ByRef $chk_matchcase, ByRef $chk_wholeonly, ByRef $pos, ByRef $occurance, ByRef $Replacements, $s_WinTitle = "", $s_WinText = "")
  222.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, 0)
  223.     Local $case = 0, $whole = 0
  224.     Local $s_text, $exact = False
  225.     Local $s_find = GUICtrlRead($Input_Search)
  226.     If $s_WinTitle <> "" Then
  227.         $s_text = ControlGetText($s_WinTitle, $s_WinText, $h_Edit)
  228.     Else
  229.         $s_text = GUICtrlRead($h_Edit)
  230.     EndIf
  231.  
  232.     If BitAND(GUICtrlRead($chk_matchcase), $GUI_CHECKED) = $GUI_CHECKED Then $case = 1
  233.     If BitAND(GUICtrlRead($chk_wholeonly), $GUI_CHECKED) = $GUI_CHECKED Then $whole = 1
  234.     If $s_find <> "" Then
  235.         $occurance += 1
  236.         $pos = StringInStr($s_text, $s_find, $case, $occurance)
  237.         If $whole And $pos Then
  238.             Local $c_compare2 = StringMid($s_text, $pos + StringLen($s_find), 1)
  239.             If $pos = 1 Then
  240.                 If ($pos + StringLen($s_find)) - 1 = StringLen($s_text) Or _
  241.                         ($c_compare2 = " " Or $c_compare2 = @LF Or $c_compare2 = @CR Or _
  242.                         $c_compare2 = @CRLF Or $c_compare2 = @TAB) Then $exact = True
  243.             Else
  244.                 Local $c_compare1 = StringMid($s_text, $pos - 1, 1)
  245.                 If ($pos + StringLen($s_find)) - 1 = StringLen($s_text) Then
  246.                     If ($c_compare1 = " " Or $c_compare1 = @LF Or $c_compare1 = @CR Or _
  247.                             $c_compare1 = @CRLF Or $c_compare1 = @TAB) Then $exact = True
  248.                 Else
  249.                     If ($c_compare1 = " " Or $c_compare1 = @LF Or $c_compare1 = @CR Or _
  250.                             $c_compare1 = @CRLF Or $c_compare1 = @TAB) And _
  251.                             ($c_compare2 = " " Or $c_compare2 = @LF Or $c_compare2 = @CR Or _
  252.                             $c_compare2 = @CRLF Or $c_compare2 = @TAB) Then $exact = True
  253.                 EndIf
  254.             EndIf
  255.             If $exact = False Then ; found word, but as part of another word, so search again
  256.                 _GuiCtrlEditFindText($h_Edit, $Input_Search, $chk_matchcase, $chk_wholeonly, $pos, $occurance, $Replacements, $s_WinTitle, $s_WinText)
  257.             Else ; found it
  258.                 _GUICtrlEditSetSel($h_Edit, $pos - 1, ($pos + StringLen($s_find)) - 1)
  259.                 _GUICtrlEditScroll($h_Edit, $SB_SCROLLCARET)
  260.             EndIf
  261.         ElseIf $whole And Not $pos Then ; no more to find
  262.             $occurance = 0
  263.             MsgBox(48, "Find", "Reached End of document, Can not find the string '" & $s_find & "'")
  264.         ElseIf Not $whole Then
  265.             If Not $pos Then ; wrap around search and select
  266.                 $occurance = 1
  267.                 _GUICtrlEditSetSel($h_Edit, -1, 0)
  268.                 _GUICtrlEditScroll($h_Edit, $SB_SCROLLCARET)
  269.                 $pos = StringInStr($s_text, $s_find, $case, $occurance)
  270.                 If Not $pos Then ; no more to find
  271.                     $occurance = 0
  272.                     MsgBox(48, "Find", "Reached End of document, Can not find the string  '" & $s_find & "'")
  273.                 Else ; found it
  274.                     _GUICtrlEditSetSel($h_Edit, $pos - 1, ($pos + StringLen($s_find)) - 1)
  275.                     _GUICtrlEditScroll($h_Edit, $SB_SCROLLCARET)
  276.                 EndIf
  277.             Else ; set selection
  278.                 _GUICtrlEditSetSel($h_Edit, $pos - 1, ($pos + StringLen($s_find)) - 1)
  279.                 _GUICtrlEditScroll($h_Edit, $SB_SCROLLCARET)
  280.             EndIf
  281.         EndIf
  282.     EndIf
  283. EndFunc   ;==>_GuiCtrlEditFindText
  284.  
  285. ;===============================================================================
  286. ;
  287. ; Description:            _GUICtrlEditGetFirstVisibleLine
  288. ; Parameter(s):        $h_edit - controlID
  289. ; Requirement:            None
  290. ; Return Value(s):    The return value is the zero-based index of the uppermost visible line in a multiline edit control.
  291. ;                            For single-line edit controls, the return value is the zero-based index of the first visible character.
  292. ; User CallTip:        _GUICtrlEditGetFirstVisibleLine($h_edit) Retrieves the zero-based index of the uppermost visible line in a multiline edit control. (required: <GuiEdit.au3>)
  293. ; Author(s):            Gary Frost (custompcs at charter dot net)
  294. ; Note(s):                The number of lines and the length of the lines in an edit control
  295. ;                            depend on the width of the control and the current Wordwrap setting.
  296. ;
  297. ;===============================================================================
  298. Func _GUICtrlEditGetFirstVisibleLine($h_Edit)
  299.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  300.     If IsHWnd($h_Edit) Then
  301.         Return _SendMessage($h_Edit, $EM_GETFIRSTVISIBLELINE)
  302.     Else
  303.         Return GUICtrlSendMsg($h_Edit, $EM_GETFIRSTVISIBLELINE, 0, 0)
  304.     EndIf
  305. EndFunc   ;==>_GUICtrlEditGetFirstVisibleLine
  306.  
  307. ;===============================================================================
  308. ;
  309. ; Description:            _GUICtrlEditGetLine
  310. ; Parameter(s):        $h_edit - controlID
  311. ;                            $i_line - Specifies the line to be retrieved.
  312. ; Requirement:            None
  313. ; Return Value(s):    Returns the line from the multiline edit control.
  314. ;                            If an error occurs, the return value is "" (empty string) and @error is set.
  315. ; User CallTip:        _GUICtrlEditGetLine($h_edit, $i_line) Copies a line of text from an edit control. (required: <GuiEdit.au3>)
  316. ; Author(s):            Gary Frost (custompcs at charter dot net)
  317. ;                            Jos van der Zande <jdeb at autoitscript com >
  318. ; Note(s):
  319. ;
  320. ;===============================================================================
  321. Func _GUICtrlEditGetLine(ByRef $h_Edit, $i_line)
  322.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, "")
  323.     Local $i_index = _GUICtrlEditLineIndex($h_Edit, $i_line)
  324.     If @error Then Return SetError($EC_ERR, $EC_ERR, "")
  325.     Local $length = _GUICtrlEditLineLength($h_Edit, $i_index)
  326.     If @error Then Return SetError($EC_ERR, $EC_ERR, "")
  327.     Local $struct_Buffer = DllStructCreate("short;char[" & $length + 2 & "]")
  328.     If @error Then Return SetError($EC_ERR, $EC_ERR, "")
  329.     DllStructSetData($struct_Buffer, 1, $length, 1)
  330.     If Not IsHWnd($h_Edit) Then $h_Edit = GUICtrlGetHandle($h_Edit)
  331.     Local $v_ret = DllCall("user32.dll", "int", "SendMessageA", "hwnd", $h_Edit, "int", $EM_GETLINE, "int", $i_line - 1, "ptr", DllStructGetPtr($struct_Buffer))
  332.     If $v_ret[0] = $EC_ERR Then Return SetError($EC_ERR, $EC_ERR, "")
  333.     Local $struct_String = DllStructCreate("char[" & $length & "]", DllStructGetPtr($struct_Buffer))
  334.     If @error Then Return SetError($EC_ERR, $EC_ERR, "")
  335.     Return DllStructGetData($struct_String, 1)
  336. EndFunc   ;==>_GUICtrlEditGetLine
  337.  
  338. ;===============================================================================
  339. ;
  340. ; Description:            _GUICtrlEditGetLineCount
  341. ; Parameter(s):        $h_edit - controlID
  342. ; Requirement:            None
  343. ; Return Value(s):    The return value is an integer specifying the total number of text lines in the multiline edit control.
  344. ; User CallTip:        _GUICtrlEditGetLineCount($h_edit) Retrieves the number of lines in a multiline edit control. (required: <GuiEdit.au3>)
  345. ; Author(s):            Gary Frost (custompcs at charter dot net)
  346. ; Note(s):                If the control has no text, the return value is 1.
  347. ;                            The return value will never be less than 1.
  348. ;
  349. ;                            The _GUICtrlEditGetLineCount retrieves the total number of text lines,
  350. ;                            not just the number of lines that are currently visible.
  351. ;
  352. ;                            If the Wordwrap feature is enabled, the number of lines can change when the dimensions of the editing window change.
  353. ;
  354. ;===============================================================================
  355. Func _GUICtrlEditGetLineCount($h_Edit)
  356.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  357.     If IsHWnd($h_Edit) Then
  358.         Return _SendMessage($h_Edit, $EM_GETLINECOUNT)
  359.     Else
  360.         Return GUICtrlSendMsg($h_Edit, $EM_GETLINECOUNT, 0, 0)
  361.     EndIf
  362. EndFunc   ;==>_GUICtrlEditGetLineCount
  363.  
  364. ;===============================================================================
  365. ;
  366. ; Description:            _GUICtrlEditGetModify
  367. ; Parameter(s):        $h_edit - controlID
  368. ; Requirement:            None
  369. ; Return Value(s):    If the contents of edit control have been modified, the return value is nonzero
  370. ;                            otherwise, it is zero.
  371. ; User CallTip:        _GUICtrlEditGetModify($h_edit) Retrieves the state of an edit control's modification flag. (required: <GuiEdit.au3>)
  372. ; Author(s):            Gary Frost (custompcs at charter dot net)
  373. ; Note(s):                The system automatically clears the modification flag to zero when the control is created.
  374. ;                            If the user changes the control's text, the system sets the flag to nonzero.
  375. ;                            You can call _GUICtrlEditSetModify to set or clear the flag.
  376. ;
  377. ;===============================================================================
  378. Func _GUICtrlEditGetModify($h_Edit)
  379.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, 0)
  380.     If IsHWnd($h_Edit) Then
  381.         Return _SendMessage($h_Edit, $EM_GETMODIFY)
  382.     Else
  383.         Return GUICtrlSendMsg($h_Edit, $EM_GETMODIFY, 0, 0)
  384.     EndIf
  385. EndFunc   ;==>_GUICtrlEditGetModify
  386.  
  387. ;===============================================================================
  388. ;
  389. ; Description:            _GUICtrlEditGetRECT
  390. ; Parameter(s):        $h_edit - controlID
  391. ; Requirement:            None
  392. ; Return Value(s):    Array containing the RECT, first element ($array[0]) contains the number of elements
  393. ;                            If an error occurs, the return value is $EC_ERR.
  394. ; User CallTip:        _GUICtrlEditGetRECT($h_edit) Retrieves the formatting rectangle of an edit control. (required: <GuiEdit.au3>)
  395. ; Author(s):            Gary Frost (custompcs at charter dot net)
  396. ; Note(s):                You can modify the formatting rectangle of a multiline edit control by using the
  397. ;                            _GUICtrlEditSetRECT.
  398. ;
  399. ;                            Under certain conditions, _GUICtrlEditGetRECT might not return the exact values that
  400. ;                            _GUICtrlEditSetRECT setùit will be approximately correct,
  401. ;                            but it can be off by a few pixels.
  402. ;
  403. ;===============================================================================
  404. Func _GUICtrlEditGetRECT($h_Edit)
  405.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  406.     #cs
  407.         typedef struct _RECT {
  408.         LONG left;
  409.         LONG top;
  410.         LONG right;
  411.         LONG bottom;
  412.         } RECT, *PRECT;
  413.     #ce
  414.     Local $left = 1, $top = 2, $right = 3, $bottom = 4
  415.     Local $struct_Rect = DllStructCreate("int;int;int;int")
  416.     If @error Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  417.     If IsHWnd($h_Edit) Then
  418.         _SendMessage($h_Edit, $EM_GETRECT, 0, DllStructGetPtr($struct_Rect))
  419.         If @error Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  420.     Else
  421.         GUICtrlSendMsg($h_Edit, $EM_GETRECT, 0, DllStructGetPtr($struct_Rect))
  422.         If @error Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  423.     EndIf
  424.     Return StringSplit(DllStructGetData($struct_Rect, $left) & "," & _
  425.             DllStructGetData($struct_Rect, $top) & "," & _
  426.             DllStructGetData($struct_Rect, $right) & "," & _
  427.             DllStructGetData($struct_Rect, $bottom), ",")
  428. EndFunc   ;==>_GUICtrlEditGetRECT
  429.  
  430. ;===============================================================================
  431. ;
  432. ; Description:            _GUICtrlEditGetSel
  433. ; Parameter(s):        $h_edit - controlID
  434. ; Requirement:            None
  435. ; Return Value(s):    Array containing the starting and ending selected positions, first element ($array[0]) contains the number of elements
  436. ;                            If an error occurs, the return value is $EC_ERR.
  437. ; User CallTip:        _GUICtrlEditGetSel($h_edit) Retrieves the starting and ending character positions of the current selection in an edit control. (required: <GuiEdit.au3>)
  438. ; Author(s):            Gary Frost (custompcs at charter dot net)
  439. ; Note(s):                $array[1] contains the starting position
  440. ;                            $array[2] contains the ending position
  441. ;
  442. ;===============================================================================
  443. Func _GUICtrlEditGetSel($h_Edit)
  444.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  445.     Local $ptr1 = "int", $ptr2 = "int", $i_ret
  446.     Local $wparam = DllStructCreate($ptr1)
  447.     Local $a_sel
  448.     If @error Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  449.     Local $lparam = DllStructCreate($ptr2)
  450.     If @error Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  451.     If IsHWnd($h_Edit) Then
  452.         $i_ret = _SendMessage($h_Edit, $EM_GETSEL, DllStructGetPtr($wparam), DllStructGetPtr($lparam))
  453.     Else
  454.         $i_ret = GUICtrlSendMsg($h_Edit, $EM_GETSEL, DllStructGetPtr($wparam), DllStructGetPtr($lparam))
  455.     EndIf
  456.     If ($i_ret == -1) Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  457.     $a_sel = StringSplit(DllStructGetData($wparam, 1) & "," & DllStructGetData($lparam, 1), ",")
  458.     Return $a_sel
  459. EndFunc   ;==>_GUICtrlEditGetSel
  460.  
  461. ;===============================================================================
  462. ;
  463. ; Description:            _GUICtrlEditLineFromChar
  464. ; Parameter(s):        $h_edit - controlID
  465. ;                            $i_index - Optional: Specifies the character index of the character contained in the line whose number is to be retrieved.
  466. ; Requirement:            None
  467. ; Return Value(s):    The return value is the zero-based line number of the line containing the character index specified by $i_index.
  468. ; User CallTip:        _GUICtrlEditLineFromChar($h_edit[, $i_index = -1]) Retrieves the index of the line that contains the specified character index in a multiline edit control. (required: <GuiEdit.au3>)
  469. ; Author(s):            Gary Frost (custompcs at charter dot net)
  470. ; Note(s):                If $i_index is û1, _GUICtrlEditLineFromChar retrieves either the line number of the current line
  471. ;                            (the line containing the caret) or, if there is a selection, the line number of the line containing
  472. ;                            the beginning of the selection.
  473. ;
  474. ;===============================================================================
  475. Func _GUICtrlEditLineFromChar($h_Edit, $i_index = -1)
  476.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  477.     If IsHWnd($h_Edit) Then
  478.         Return _SendMessage($h_Edit, $EM_LINEFROMCHAR, $i_index)
  479.     Else
  480.         Return GUICtrlSendMsg($h_Edit, $EM_LINEFROMCHAR, $i_index, 0)
  481.     EndIf
  482. EndFunc   ;==>_GUICtrlEditLineFromChar
  483.  
  484. ;===============================================================================
  485. ;
  486. ; Description:            _GUICtrlEditLineIndex
  487. ; Parameter(s):        $h_edit - controlID
  488. ;                            $i_line - Optional: Specifies the zero-based line number.
  489. ;                                        A value of û1 specifies the current line number (the line that contains the caret).
  490. ; Requirement:            None
  491. ; Return Value(s):    The return value is the character index of the line specified in the wParam parameter,
  492. ;                            or it is $EC_ERR if the specified line number is greater than the number of lines in the edit control.
  493. ; User CallTip:        _GUICtrlEditLineIndex($h_edit[, $i_line = -1]) Retrieves the character index of the first character of a specified line in a multiline edit control. (required: <GuiEdit.au3>)
  494. ; Author(s):            Gary Frost (custompcs at charter dot net)
  495. ; Note(s):
  496. ;
  497. ;===============================================================================
  498. Func _GUICtrlEditLineIndex($h_Edit, $i_line = -1)
  499.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  500.     If IsHWnd($h_Edit) Then
  501.         Return _SendMessage($h_Edit, $EM_LINEINDEX, $i_line)
  502.     Else
  503.         Return GUICtrlSendMsg($h_Edit, $EM_LINEINDEX, $i_line, 0)
  504.     EndIf
  505. EndFunc   ;==>_GUICtrlEditLineIndex
  506.  
  507. ;===============================================================================
  508. ;
  509. ; Description:            _GUICtrlEditLineLength
  510. ; Parameter(s):        $h_edit - controlID
  511. ;                            $i_index - Optional: Specifies the character index of a character in the line whose length is to be retrieved.
  512. ; Requirement:            None
  513. ; Return Value(s):    For multiline edit controls, the return value is the length, in TCHARs, of the line specified by the $i_index parameter.
  514. ;                            For single-line edit controls, the return value is the length, in TCHARs, of the text in the edit control.
  515. ; User CallTip:        _GUICtrlEditLineLength($h_edit[, $i_index = -1]) Retrieves the length, in characters, of a line in an edit control. (required: <GuiEdit.au3>)
  516. ; Author(s):            Gary Frost (custompcs at charter dot net)
  517. ; Note(s):                $i_index
  518. ;                                For ANSI text, this is the number of bytes
  519. ;                                For Unicode text, this is the number of characters.
  520. ;                                It does not include the carriage-return character at the end of the line.
  521. ;                                If $i_index is greater than the number of characters in the control, the return value is zero.
  522. ;
  523. ;===============================================================================
  524. Func _GUICtrlEditLineLength($h_Edit, $i_index = -1)
  525.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, $EC_ERR)
  526.     If IsHWnd($h_Edit) Then
  527.         Return _SendMessage($h_Edit, $EM_LINELENGTH, $i_index)
  528.     Else
  529.         Return GUICtrlSendMsg($h_Edit, $EM_LINELENGTH, $i_index, 0)
  530.     EndIf
  531. EndFunc   ;==>_GUICtrlEditLineLength
  532.  
  533. ;===============================================================================
  534. ;
  535. ; Description:            _GUICtrlEditLineScroll
  536. ; Parameter(s):        $h_edit - controlID
  537. ;                            $i_horiz - Specifies the number of characters to scroll horizontally.
  538. ;                            $i_vert - Specifies the number of lines to scroll vertically.
  539. ; Requirement:            None
  540. ; Return Value(s):    If the message is sent to a multiline edit control, the return value is TRUE.
  541. ;                            If the message is sent to a single-line edit control, the return value is FALSE.
  542. ; User CallTip:        _GUICtrlEditLineScroll($h_edit, $i_horiz, $i_vert) Scrolls the text in a multiline edit control. (required: <GuiEdit.au3>)
  543. ; Author(s):            Gary Frost (custompcs at charter dot net)
  544. ; Note(s):                The control does not scroll vertically past the last line of text in the edit control.
  545. ;                            If the current line plus the number of lines specified by the $i_vert parameter exceeds the total number of lines in the edit control,
  546. ;                            the value is adjusted so that the last line of the edit control is scrolled to the top of the edit-control window.
  547. ;
  548. ;                            _GUICtrlEditLineScroll scrolls the text vertically or horizontally in a multiline edit control.
  549. ;                            _GUICtrlEditLineScroll can be used to scroll horizontally past the last character of any line.
  550. ;
  551. ;===============================================================================
  552. Func _GUICtrlEditLineScroll($h_Edit, $i_horiz, $i_vert)
  553.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, False)
  554.     If IsHWnd($h_Edit) Then
  555.         Return _SendMessage($h_Edit, $EM_LINESCROLL, $i_horiz, $i_vert)
  556.     Else
  557.         Return GUICtrlSendMsg($h_Edit, $EM_LINESCROLL, $i_horiz, $i_vert)
  558.     EndIf
  559. EndFunc   ;==>_GUICtrlEditLineScroll
  560.  
  561. ;===============================================================================
  562. ;
  563. ; Description:            _GUICtrlEditReplaceSel
  564. ; Parameter(s):        $h_edit - controlID
  565. ;                    $i_bool - Specifies whether the replacement operation can be undone.
  566. ;                                        If this is TRUE, the operation can be undone.
  567. ;                                        If this is FALSE , the operation cannot be undone.
  568. ;                            $s_text - String containing the replacement text.
  569. ; Requirement:            None
  570. ; Return Value(s):    None
  571. ; User CallTip:        _GUICtrlEditReplaceSel($h_edit, $i_bool, $s_text) Replaces the current selection in an edit control with the specified text. (required: <GuiEdit.au3>)
  572. ; Author(s):            Gary Frost (custompcs at charter dot net)
  573. ; Note(s):                Use the _GUICtrlEditReplaceSel to replace only a portion of the text in an edit control.
  574. ;                            If there is no current selection, the replacement text is inserted at the current location of the caret.
  575. ;
  576. ;===============================================================================
  577. Func _GUICtrlEditReplaceSel($h_Edit, $i_bool, $s_text)
  578.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, 0)
  579.     If IsHWnd($h_Edit) Then
  580.         Local $struct_MemMap
  581.         Local $struct_String = DllStructCreate("char[" & StringLen($s_text) + 1 & "]")
  582.         If @error Then Return SetError($EC_ERR, $EC_ERR, 0)
  583.         Local $sBuffer_pointer = DllStructGetPtr($struct_String)
  584.         DllStructSetData($struct_String, 1, $s_text)
  585.         _MemInit ($h_Edit, StringLen($s_text) + 1, $struct_MemMap)
  586.         If @error Then
  587.             _MemFree ($struct_MemMap)
  588.             Return SetError($EC_ERR, $EC_ERR, 0)
  589.         EndIf
  590.         _MemWrite ($struct_MemMap, $sBuffer_pointer)
  591.         If @error Then
  592.             _MemFree ($struct_MemMap)
  593.             Return SetError($EC_ERR, $EC_ERR, 0)
  594.         EndIf
  595.         _SendMessage($h_Edit, $EM_REPLACESEL, $i_bool, $sBuffer_pointer)
  596.         If @error Then
  597.             _MemFree ($struct_MemMap)
  598.             Return SetError($EC_ERR, $EC_ERR, 0)
  599.         EndIf
  600.         _MemFree ($struct_MemMap)
  601.         If @error Then Return SetError($EC_ERR, $EC_ERR, 0)
  602. ;~         _SendMessage($h_Edit, $EM_REPLACESEL, $i_bool, $s_text)
  603.     Else
  604.         GUICtrlSendMsg($h_Edit, $EM_REPLACESEL, $i_bool,String( $s_text))
  605.     EndIf
  606. EndFunc   ;==>_GUICtrlEditReplaceSel
  607.  
  608. ;===============================================================================
  609. ;
  610. ; Description:            _GUICtrlEditScroll
  611. ; Parameter(s):        $h_edit - controlID
  612. ;                            $i_direct - Specifies the action the scroll bar is to take.
  613. ; Requirement:            None
  614. ; Return Value(s):    If successful, the high-order word of the return value is TRUE, and the low-order word is the number of lines that the command scrolls.
  615. ;                            If the $i_direct parameter specifies an invalid value, the return value is FALSE.
  616. ; User CallTip:        _GUICtrlEditScroll($h_edit, $i_direct) Scrolls the text vertically in a multiline edit control. (required: <GuiEdit.au3>)
  617. ; Author(s):            Gary Frost (custompcs at charter dot net)
  618. ; Note(s):                $i_direct
  619. ;                                This parameter can be one of the following values.
  620. ;                                    $SB_LINEDOWN
  621. ;                                        Scrolls down one line.
  622. ;                                    $SB_LINEUP
  623. ;                                        Scrolls up one line.
  624. ;                                    $SB_PAGEDOWN
  625. ;                                        Scrolls down one page.
  626. ;                                    $SB_PAGEUP
  627. ;                                        Scrolls up one page.
  628. ;                                    $SB_SCROLLCARET
  629. ;                                        Scrolls the caret into view
  630. ;
  631. ;                            To scroll to a specific line or character position, use the _GUICtrlEditLineSscroll.
  632. ;
  633. ;===============================================================================
  634. Func _GUICtrlEditScroll($h_Edit, $i_direct)
  635.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, False)
  636.     If IsHWnd($h_Edit) Then
  637.         If $i_direct == $SB_SCROLLCARET Then
  638.             Return _SendMessage($h_Edit, $EM_SCROLLCARET)
  639.         Else
  640.             Return _SendMessage($h_Edit, $EM_SCROLL, $i_direct)
  641.         EndIf
  642.     Else
  643.         If $i_direct == $SB_SCROLLCARET Then
  644.             Return GUICtrlSendMsg($h_Edit, $EM_SCROLLCARET, 0, 0)
  645.         Else
  646.             Return GUICtrlSendMsg($h_Edit, $EM_SCROLL, $i_direct, 0)
  647.         EndIf
  648.     EndIf
  649. EndFunc   ;==>_GUICtrlEditScroll
  650.  
  651. ;===============================================================================
  652. ;
  653. ; Description:            _GUICtrlEditSetModify
  654. ; Parameter(s):        $h_edit - controlID
  655. ;                            $i_bool - Specifies the new value for the modification flag.
  656. ;                                        A value of TRUE indicates the text has been modified.
  657. ;                                        A value of FALSE indicates it has not been modified.
  658. ; Requirement:            None
  659. ; Return Value(s):    None
  660. ; User CallTip:        _GUICtrlEditSetModify($h_edit, $i_bool) Sets or clears the modification flag for an edit control. (required: <GuiEdit.au3>)
  661. ; Author(s):            Gary Frost (custompcs at charter dot net)
  662. ; Note(s):                The system automatically clears the modification flag to zero when the control is created.
  663. ;                            If the user changes the control's text, the system sets the flag to nonzero.
  664. ;                            You can use the _GUICtrlEditGetModify to retrieve the current state of the flag.
  665. ;
  666. ;===============================================================================
  667. Func _GUICtrlEditSetModify($h_Edit, $i_bool)
  668.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, False)
  669.     If IsHWnd($h_Edit) Then
  670.         _SendMessage($h_Edit, $EM_SETMODIFY, $i_bool)
  671.     Else
  672.         GUICtrlSendMsg($h_Edit, $EM_SETMODIFY, $i_bool, 0)
  673.     EndIf
  674. EndFunc   ;==>_GUICtrlEditSetModify
  675.  
  676. ;===============================================================================
  677. ;
  678. ; Description:            _GUICtrlEditSetRECT
  679. ; Parameter(s):        $h_edit - controlID
  680. ;                            $left - Specifies the x-coordinate of the upper-left corner of the rectangle.
  681. ;                            $top - Specifies the y-coordinate of the upper-left corner of the rectangle.
  682. ;                            $right - Specifies the x-coordinate of the lower-right corner of the rectangle.
  683. ;                            $bottom - Specifies the y-coordinate of the lower-right corner of the rectangle.
  684. ; Requirement:            None
  685. ; Return Value(s):    None
  686. ; User CallTip:        _GUICtrlEditSetRECT(Byref $h_edit, $left, $top, $right, $bottom) Sets the formatting rectangle of an edit control. (required: <GuiEdit.au3>)
  687. ; Author(s):            Gary Frost (custompcs at charter dot net)
  688. ; Note(s):
  689. ;
  690. ;===============================================================================
  691. Func _GUICtrlEditSetRECT(ByRef $h_Edit, $left, $top, $right, $bottom)
  692.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, 0)
  693.     Local Const $EM_SETRECT = 0xB3
  694.     Local $struct = DllStructCreate("int;int;int;int")
  695.     DllStructSetData($struct, 1, $left)
  696.     DllStructSetData($struct, 2, $top)
  697.     DllStructSetData($struct, 3, $right + 1)
  698.     DllStructSetData($struct, 4, $bottom + 10)
  699.     If IsHWnd($h_Edit) Then
  700.         _SendMessage($h_Edit, $EM_SETRECT, 0, DllStructGetPtr($struct))
  701.     Else
  702.         GUICtrlSendMsg($h_Edit, $EM_SETRECT, 0, DllStructGetPtr($struct))
  703.     EndIf
  704. EndFunc   ;==>_GUICtrlEditSetRECT
  705.  
  706. ;===============================================================================
  707. ;
  708. ; Description:            _GUICtrlEditSetSel
  709. ; Parameter(s):        $h_edit - controlID
  710. ;                            $i_start - Specifies the starting character position of the selection.
  711. ;                            $i_end - Specifies the ending character position of the selection.
  712. ; Requirement:            None
  713. ; Return Value(s):    None
  714. ; User CallTip:        _GUICtrlEditSetSel($h_edit, $i_start, $i_end) Selects a range of characters in an edit control. (required: <GuiEdit.au3>)
  715. ; Author(s):            Gary Frost (custompcs at charter dot net)
  716. ; Note(s):                The start value can be greater than the end value.
  717. ;                            The lower of the two values specifies the character position of the first character in the selection.
  718. ;                            The higher value specifies the position of the first character beyond the selection.
  719. ;
  720. ;                            The start value is the anchor point of the selection, and the end value is the active end.
  721. ;                            If the user uses the SHIFT key to adjust the size of the selection, the active end can move but the anchor point remains the same.
  722. ;
  723. ;                            If the $i_start is 0 and the $i_end is û1, all the text in the edit control is selected.
  724. ;                            If the $i_start is û1, any current selection is deselected.
  725. ;
  726. ;                            The control displays a flashing caret at the $i_end position regardless of the relative values of $i_start and $i_end.
  727. ;
  728. ;===============================================================================
  729. Func _GUICtrlEditSetSel($h_Edit, $i_start, $i_end)
  730.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, 0)
  731.     If IsHWnd($h_Edit) Then
  732.         _SendMessage($h_Edit, $EM_SETSEL, $i_start, $i_end)
  733.     Else
  734.         GUICtrlSendMsg($h_Edit, $EM_SETSEL, $i_start, $i_end)
  735.     EndIf
  736. EndFunc   ;==>_GUICtrlEditSetSel
  737.  
  738. ;===============================================================================
  739. ;
  740. ; Description:            _GUICtrlEditUndo
  741. ; Parameter(s):        $h_edit - controlID
  742. ; Requirement:            None
  743. ; Return Value(s):    For a single-line edit control, the return value is always TRUE.
  744. ;                            For a multiline edit control, the return value is TRUE if the undo operation is successful,
  745. ;                            or FALSE if the undo operation fails.
  746. ; User CallTip:        _GUICtrlEditUndo($h_edit) Undoes the last edit control operation in the control's undo queue. (required: <GuiEdit.au3>)
  747. ; Author(s):            Gary Frost (custompcs at charter dot net)
  748. ; Note(s):                An undo operation can also be undone.
  749. ;                            For example, you can restore deleted text with the first _GUICtrlEditUndo,
  750. ;                            and remove the text again with a second _GUICtrlEditUndo as long as there
  751. ;                            is no intervening edit operation.
  752. ;
  753. ;===============================================================================
  754. Func _GUICtrlEditUndo($h_Edit)
  755.     If Not _IsClassName ($h_Edit, "Edit") Then Return SetError($EC_ERR, $EC_ERR, False)
  756.     If IsHWnd($h_Edit) Then
  757.         Return _SendMessage($h_Edit, $EM_UNDO)
  758.     Else
  759.         Return GUICtrlSendMsg($h_Edit, $EM_UNDO, 0, 0)
  760.     EndIf
  761. EndFunc   ;==>_GUICtrlEditUndo